﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Ducu.UI.Responsible
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "HomePage",
                "Page-{pageIndex}",
                new { controller = "Plan", action = "Index" },
                new { pageIndex = @"\d+" }
            );

            #region URL: /Plan

            routes.MapRoute(
                "PlanShow",
                "Plan/{id}",
                new { controller = "Plan", action = "Show" },
                new { id = @"\d+" }
            );

            routes.MapRoute(
                "PlanIndex",
                "Plan/Page-{pageIndex}",
                new { controller = "Plan", action = "Index" }
            );

            #endregion

            #region URL: /Task

            routes.MapRoute(
                "TaskFulfil",
                "Task/Fulfil/{planId}",
                new { controller = "Task", action = "Fulfil" },
                new { planId = @"\d+" }
            );

            routes.MapRoute(
                "TaskAccept",
                "Task/Accept/{planId}",
                new { controller = "Task", action = "Accept" },
                new { planId = @"\d+" }
            );

            routes.MapRoute(
                "TaskHistoryListPaged",
                "Task/History/List/{planId}/Page-{pageIndex}",
                new { controller = "Task", action = "HistoryList" },
                new { planId = @"\d+", pageIndex = @"\d+" }
            );
            
            routes.MapRoute(
                "TaskHistoryList",
                "Task/History/List/{planId}",
                new { controller = "Task", action = "HistoryList" },
                new { planId = @"\d+" }
            );

            routes.MapRoute(
                "TaskHistoryMonth",
                "Task/History/Month/{planId}/{year}/{month}",
                new { controller = "Task", action = "HistoryMonth" },
                new { planId = @"\d+", year = @"\d+", month = @"\d+" }
            );

            #endregion

            #region URL: /User

            routes.MapRoute(
                "UserCreditPaged",
                "User/Credits/{userId}/Page-{pageIndex}",
                new { controller = "User", action = "Credits" },
                new { pageIndex = @"\d+" }
            );
            
            routes.MapRoute(
                "UserCredit",
                "User/Credits/{userId}",
                new { controller = "User", action = "Credits" }
            );

            #endregion

            routes.MapRoute(
                name: "Paged",
                url: "{controller}/{action}/Page-{pageIndex}",
                defaults: new { },
                constraints: new { pageIndex = @"\d+" }
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Plan", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}
